import absevnt from '../abseventsvc.js'
import rightmenumainaction from './RMouseAction/rightmenumainaction.js'
class RMosUpSvc extends absevnt.IEventSvc {
    constructor() {
        super();
    }
    act(canvasEvt) {
        console.log("RMosUpSelGraphSvc:xxx---------");
        let clickRightHtml = document.getElementsByClassName('clickRightMenu')[0];

        while (clickRightHtml.firstChild) {
            clickRightHtml.removeChild(clickRightHtml.firstChild);
        }

        this.createRMenu(clickRightHtml, canvasEvt);
        clickRightHtml.style.display = "block";
        clickRightHtml.style.position = "absolute";
        clickRightHtml.style.left = canvasEvt.scrnx + "px";
        clickRightHtml.style.top = canvasEvt.scrny + "px";
        window.mainctl.forbidMouseMove = true;
    }

    createRMenu(clickRightHtml, canvasEvt) {
        this.addItem(clickRightHtml, "pick", "选择");
        this.addItem(clickRightHtml, "pan", "漫游");
        this.addItem(clickRightHtml, "undo", "撤销");
        this.addItem(clickRightHtml, "redo", "回退");
        this.addItem(clickRightHtml, "paste", "粘贴");
    }

    addItem(clickRightHtml, subItem, title) {
        let editpropItem = document.getElementById(subItem);
        if (!editpropItem) {
            editpropItem = document.createElement('li');
            clickRightHtml.appendChild(editpropItem);
            editpropItem.id = subItem;
            editpropItem.innerHTML = title;
        }
        if (!window.mainctl.m_pRMenuINTF.chkItemCanDis(subItem)) {
            clickRightHtml.removeChild(editpropItem);
        }

        editpropItem.addEventListener('click', function (evt) {
            clickRightHtml.style.display = "none";
            rightmenumainaction.RightMenuMainAction.act2Click(window.mainctl, evt, subItem);
            window.mainctl.forbidMouseMove = false;
        });
    }
}

export default { RMosUpSvc }